package cn.sunzq.springdata.elasticsearch.demo.querydemo.controller;

import cn.sunzq.springdata.elasticsearch.demo.base.response.ResponseDTO;
import cn.sunzq.springdata.elasticsearch.demo.querydemo.enums.ClientTypeEnum;
import cn.sunzq.springdata.elasticsearch.demo.querydemo.service.QueryDemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @创建人 孙中泉
 * @创建时间 2021/7/26
 * @描述
 */
@RestController
@RequestMapping("/queryDemo")
public class QueryDemoController {

    @Autowired
    private QueryDemoService queryDemoService;

    @RequestMapping(value = "/indexExist/{indexName}/{clientType}", method = RequestMethod.GET, produces = "application/json;charset=utf-8")
    public ResponseDTO<Boolean> indexExist(@PathVariable("indexName") String indexName, @PathVariable(value = "clientType", required = false) Integer clientType){
        return queryDemoService.indexExist(indexName, clientType == null ? ClientTypeEnum.ElasticsearchOperations.getCode():clientType);
    }

    @RequestMapping(value = "/createIndex/{indexName}/{clientType}", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    public ResponseDTO<Boolean> createIndex(@PathVariable("indexName") String indexName,
                                           @PathVariable(value = "clientType", required = false) Integer clientType){
        return queryDemoService.createIndex(indexName, clientType == null ? ClientTypeEnum.ElasticsearchOperations.getCode():clientType);
    }

}
